package com.yupi.springbootinit.service;

import com.yupi.springbootinit.mapper.ProductionOperationRecordMapper;
import com.yupi.springbootinit.model.entity.ProductionOperationRecord;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class ProductionOperationRecordService {

    @Resource
    private ProductionOperationRecordMapper recordMapper;

    public void recordStart(Long taskId, Long batchId, Long stepId, Integer operationSeq,
                            String execType, Long operatorId, String operatorName,
                            Long createdBy, String createdByName, String remark) {
        ProductionOperationRecord r = new ProductionOperationRecord();
        r.setTaskId(taskId);
        r.setBatchId(batchId);
        r.setStepId(stepId);
        r.setOperationSeq(operationSeq);
        r.setExecType(execType);
        r.setEventType("START");
        r.setEventTime(new Date());
        r.setOperatorId(operatorId);
        r.setOperatorName(operatorName);
        r.setCreatedBy(createdBy);
        r.setCreatedByName(createdByName);
        r.setRemark(remark);
        r.setCreateTime(new Date());
        r.setUpdateTime(new Date());
        r.setIsDelete(0);
        recordMapper.insert(r);
    }

    public void recordComplete(Long taskId, Long batchId, Long stepId, Integer operationSeq,
                               String execType, Long operatorId, String operatorName,
                               Long createdBy, String createdByName, String remark) {
        ProductionOperationRecord r = new ProductionOperationRecord();
        r.setTaskId(taskId);
        r.setBatchId(batchId);
        r.setStepId(stepId);
        r.setOperationSeq(operationSeq);
        r.setExecType(execType);
        r.setEventType("COMPLETE");
        r.setEventTime(new Date());
        r.setOperatorId(operatorId);
        r.setOperatorName(operatorName);
        r.setCreatedBy(createdBy);
        r.setCreatedByName(createdByName);
        r.setRemark(remark);
        r.setCreateTime(new Date());
        r.setUpdateTime(new Date());
        r.setIsDelete(0);
        recordMapper.insert(r);
    }

}